package com.cskaoyan.service.vx;

import com.cskaoyan.bean.bo.vxBo.FootPrintBO;
import com.cskaoyan.bean.bo.vxBo.FootPrintBO2;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.wxPo.MarketFootprint;
import com.cskaoyan.bean.po.wxPo.MarketUser;
import com.cskaoyan.bean.vo.KeywordVO;
import com.cskaoyan.bean.vo.vxVo.FootPrintVO;
import com.cskaoyan.mapper.wxMapper.MarketFeedbackMapper;
import com.cskaoyan.mapper.wxMapper.MarketFootprintMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class FootPrintServiceImpl implements FootPrintService{

    @Autowired
    MarketFootprintMapper marketFootprintMapper;


    @Override
    public FootPrintVO quaryFootPrint(BaseParam baseParam) {
        FootPrintVO footPrintVO = new FootPrintVO();
        PageHelper.startPage(baseParam.getPage(),baseParam.getLimit());
        Subject subject = SecurityUtils.getSubject();
        MarketUser marketUser = (MarketUser) subject.getPrincipals().getPrimaryPrincipal();
        Integer userId = marketUser.getId();
        List<FootPrintBO> footPrintBOS = marketFootprintMapper.selectFootPrint(userId);
        List<FootPrintBO> footPrintBOS1 = new ArrayList<>();
        for (FootPrintBO footPrintBO : footPrintBOS) {
            FootPrintBO footPrintBO1 = new FootPrintBO();
            footPrintBO1.setAddTime(footPrintBO.getAddTime());
            footPrintBO1.setBrief(footPrintBO.getBrief());
            footPrintBO1.setGoodsId(footPrintBO.getGoodsId());
            footPrintBO1.setId(footPrintBO.getId());
            footPrintBO1.setName(footPrintBO.getName());
            footPrintBO1.setPicUrl(footPrintBO.getPicUrl());
            footPrintBO1.setRetailPrice(footPrintBO.getRetailPrice());
            footPrintBOS1.add(footPrintBO1);
        }
        PageInfo pageInfo = new PageInfo(footPrintBOS);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        footPrintVO.setTotal((int) total);
        footPrintVO.setPage(baseParam.getPage());
        footPrintVO.setPages(pages);
        footPrintVO.setLimit(baseParam.getLimit());
        footPrintVO.setList(footPrintBOS1);
        return footPrintVO;

    }

    @Override
    public void deleteFootPrint(MarketFootprint marketFootprint) {
        int count  = marketFootprintMapper.deleteFootprint(marketFootprint);
    }

}
